package gsp420;
import java.io.FileReader;
import java.io.IOException;
public class FileIOTest {
	public static boolean isNumber(String s){
		boolean isNumber = true;
		for(int i = 0; isNumber && i < s.length(); ++i)
			switch(s.charAt(i)){
			case '0':	case '1':	case '2':	case '3':	case '4':
			case '5':	case '6':	case '7':	case '8':	case '9':	break;
			case '-':	if(i != 0)	isNumber = false;
			default:				isNumber = false;
			}
		return isNumber;
	}
	public static void main(String[] args)
	{
        FileReader inputStream = null;
        try {
            inputStream = new FileReader("text.txt");
            int c;
            StringBuffer buff = new StringBuffer();
            while ((c = inputStream.read()) != -1) {
            	buff.append((char)c);
            }
            String s = buff.toString();
            String[] strings = s.split(" |\r\n|\n|\r");
            for (String string : strings) {
				System.out.println("["+string+"]");
				boolean b = isNumber(string);// could be inlined with refactor tools
				if(b)
				{
					int number = Integer.parseInt(string);
					System.out.println("the number "+number);
				}
			}
        } catch (IOException e){}
        finally {
            try {
	            if (inputStream != null) {
						inputStream.close();
	            }
			} catch (IOException e) {
				e.printStackTrace();
			}
        }
	}
}
